home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 49 / Amiga Format CD49 (2000-01-17)(Future Publishing)(GB)(Track 1 of 3)[!][issue 2000-02].iso / -serious- / comms / other / dc-sx107install / sx / developer / assembler / ximdoor.s < prev   
Text File  |  1999-11-29  |  3KB  |  155 lines

  1. ;
  2. ; SYSTEM-X Door (XIM) Written By Zed/DC
  3. ;
  4. ; Don't tell me this source looks really bad! This is the first program
  5. ; I've written in ASM, so it's ok for that eh? :)
  6. ;
  7. ; Note: this example uses door command 1500, which is for System-X
  8. ;       only. It will not work on AmiExpress.
  9.  
  10.     ;incdir "include:"        ; <-- use this for ASM-One
  11.     include "exec/exec_lib.i"
  12.     include "exec/ports.i"
  13.     include "libraries/dos_lib.i"
  14.  
  15.     STRUCTURE    XIMMsg,0
  16.     STRUCT        Node,LN_SIZE
  17.     APTR        ReplyPort
  18.     UWORD        Length
  19.     STRUCT        Str,200
  20.     LONG        Data
  21.     LONG        Command
  22.     LABEL        bufsize
  23.  
  24.  
  25. ExecBase    EQU    $4
  26.  
  27.     SECTION ximdoor,code
  28.  
  29.     clr.b    -1(a0,d0.L)        ; add null to arg
  30.     move.l    a0,d0            ; arg string is the node number
  31.     lea    portmask(PC),a0
  32.     bsr    sprintf
  33.  
  34.     lea    dosname(PC),a1
  35.     moveq    #0,d0            ; version 0
  36.     jsr    _LVOOpenLibrary(A6)
  37.     movea.l    d0,a5            ; store dosbase in a5
  38.  
  39.     lea    buffer(PC),a1
  40.     jsr    _LVOFindPort(A6)
  41.     tst.l    d0
  42.     beq    error
  43.     movea.l    d0,a4            ; store *Port in a4
  44.  
  45.     sub    #bufsize,sp        ; grab stack memory
  46.     lea    (sp),a3            ; our memory ptr to a3
  47.  
  48.     jsr    _LVOCreateMsgPort(A6)
  49.     move.l    d0,ReplyPort(A3)    ; create reply port
  50.  
  51.     move    #bufsize,Length(A3)
  52.     move.l    #1,Command(A3)        ; 1 = Startup
  53.     bsr    putmsg
  54.     clr.b    Str(A3)            ; erase string
  55.  
  56. ; ---------------------------------------------------------------
  57. ; ==================== MAIN DOOR CODE HERE ======================
  58. ; ---------------------------------------------------------------
  59.  
  60.     lea    welcome(PC),a1
  61.     bsr    print            ; print the string welcome
  62.  
  63.     lea    prompt(PC),a1
  64.     moveq    #30,d1
  65.     bsr    getinput        ; get input, max 30 chars
  66.  
  67.     lea    youenter(PC),a1
  68.     bsr    print            ; print the string youenter
  69.  
  70.     lea    Str(A3),a1    ; what the user typed is in Str + A3
  71.     bsr    print            ; print what they typed
  72.  
  73.     lea    doublecr(PC),a1
  74.     bsr    print            ; print a couple CR's
  75.  
  76. ; -------------------------------------------------------------
  77. ; ===================== END OF MAIN CODE ======================
  78. ; -------------------------------------------------------------
  79.  
  80.     move.l    #2,Command(A3)        ; 2 = Shutdown
  81.     bsr    putmsg
  82.  
  83.     move.l    ReplyPort(A3),a0
  84.     jsr    _LVODeleteMsgPort(A6)    ; kill reply port
  85.  
  86.     add    #bufsize,sp        ; return memory to stack
  87.     bsr    exit
  88.     rts
  89.  
  90. getinput
  91.     lea    Str(A3),a0
  92.     bsr    strcpy
  93.     move.l    #5,Command(A3)
  94.     move.l    d1,Data(A3)
  95.     bsr    putmsg
  96.     rts
  97.  
  98. print
  99.     move.l    #1500,Command(A3)    ;    1500 = print string
  100.     move.l    a1,Data(A3)
  101.  
  102. putmsg
  103.     move.l    a4,a0
  104.     move.l    a3,a1
  105.     jsr    _LVOPutMsg(A6)
  106.  
  107.     move.l    ReplyPort(A3),a0
  108.     jsr    _LVOWaitPort(A6)
  109.  
  110.     move.l    ReplyPort(A3),a0
  111.     jsr    _LVOGetMsg(A6)
  112.     rts
  113.  
  114. error
  115.     move.l    a5,a6
  116.     lea    errormsg(PC),a1
  117.     move.l    a1,d1
  118.     jsr    _LVOPutStr(A6)
  119.     movea.l    (ExecBase).W,a6
  120.  
  121. exit
  122.     move.l    a5,a1
  123.     jsr    _LVOCloseLibrary(A6)
  124.     rts
  125.  
  126. sprintf
  127.     movem.l    D0-D3/A0-A3,-(SP)
  128.     move.l    SP,A1
  129.     lea    PutChar(PC),A2
  130.     lea    buffer(PC),A3
  131.     movea.l    (ExecBase).W,A6
  132.     jsr    _LVORawDoFmt(A6)
  133.     movem.l    (SP)+,D0-D3/A0-A3
  134.     rts
  135.  
  136. PutChar
  137.     move.b    d0,(a3)+
  138.     rts
  139.  
  140. strcpy
  141.     move.b    (A1)+,(A0)+        ; copy a1 to a0 (string copy)
  142.     bne.s    strcpy
  143.     rts
  144.  
  145. buffer:        dc.b    "$VER: XIMDoor 1.0",0
  146. dosname:    dc.b    "dos.library",0
  147. errormsg:    dc.b    "This must be run from System-X BBS!",10,0
  148. portmask:    dc.b    "AEDoorPort%s",0
  149. welcome:    dc.b    13,10,"This is a lame door!!",13,10,0
  150. prompt:        dc.b    13,10,"Enter some text: ",0
  151. youenter:    dc.b    13,10,"You entered: ",0
  152. doublecr:    dc.b    13,10,13,10,0
  153.         even            ; or "align" in some assemblers
  154.         end
  155.